<template>
  <div class="page-container">
    <!--主页面列表-->
    <div>
      <!--工具栏-->
      <div class="toolbar">
        <el-form :inline="true" :model="filters" :size="size" ref="filters">
          <!-- 搜索框部分 -->
          <el-row class="search-input">
            <el-form-item class="commonStyle" label="商品名称：">
              <el-input v-model="filters.chineseName" placeholder="商品名称" maxlength="80" clearable></el-input>
            </el-form-item>
            <el-form-item class="commonStyle" label="商品编码：">
              <el-input v-model="filters.code" placeholder="商品编码" maxlength="80" clearable></el-input>
            </el-form-item>
            <el-form-item label="商品品牌：">
               <el-input v-model="filters.brandName" placeholder="商品品牌"  @focus="queryBrand()"></el-input>
             <!--  <el-select v-model="filters.brandId" filterable placeholder="商品品牌" clearable >
                <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" ></el-option>
              </el-select> -->
            </el-form-item>
            <el-form-item label="商品类型：">
              <el-select v-model="filters.type" filterable placeholder="商品类型" clearable>
                <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商品形式：">
              <el-select
                v-model="filters.typeOfProduct"
                filterable
                placeholder="商品形式"
                clearable
              >
                <el-option
                  v-for="item in typeOfProductList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="商品类目：">
              <el-select v-model="mineStatus" placeholder="请选择"    collapse-tags >
                <el-option :value="filters.categoryIdArr" style="height: auto">
                  <el-tree :data="selectCategoryData" accordion  show-checkbox node-key="id"   highlight-current :props="defaultProps" @check="(click, checked)=>{handleCheckChange(click, checked)}"></el-tree>
                </el-option>
              </el-select>
            </el-form-item>
<!--             <el-form-item label="允许销售：">
              <el-select
                v-model="filters.canSale"
                filterable
                placeholder="允许销售"
                clearable
              >
                <el-option
                  v-for="item in isSaleOptions"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item label="商品来源：">
              <el-select
                v-model="filters.sourceType"
                filterable
                placeholder="商品来源"
                clearable
              >
                <el-option
                  v-for="item in sourceTypeOptions"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商户：">
              <el-select
                v-model="filters.product"
                filterable
                placeholder="商户 "
                clearable
              >
                <el-option
                  v-for="item in productOptions"
                  :key="item.key"
                  :label="item.value"
                  :value="item.key"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <!-- 查询 刷新 部分 -->
          <el-row class="search-button">
            <el-form-item>
              <kt-button  icon="fa fa-search" :label="$t('action.search')" type="primary" @click="findPage()"></kt-button>
            </el-form-item>
            <el-form-item>
              <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')"></kt-button>
            </el-form-item>
            <el-form-item>
              <kt-button icon="fa fa-plus" :label="$t('action.add')" type="primary" @click="handleAdd()"></kt-button>
            </el-form-item>
             <el-form-item>
              <el-button icon="el-icon-upload2" type="primary" @click="handleDistribution()">批量新增商品</el-button>
            </el-form-item>
             <el-form-item>
              <el-button icon="el-icon-document-add" type="primary" @click="handleDistribution()">批量导入图片</el-button>
            </el-form-item>
           <!--  <el-form-item>
              <el-button icon="el-icon-s-shop" type="primary" @click="handleDistribution()">分配</el-button>
            </el-form-item> -->
          </el-row>
          <!--tab切换-->
          <div>
            <el-row class=" button mt20 noboder">
              <el-form-item>
                 <el-tabs v-model="activeName"  type="card"  @tab-click="handTabChange">
                  <el-tab-pane label="全部" name="1"></el-tab-pane>
                  <el-tab-pane label="预审核" name="4"></el-tab-pane>
                  <el-tab-pane label="待审核" name="5"></el-tab-pane>
                  <el-tab-pane label="审核通过" name="6"></el-tab-pane>
                  <el-tab-pane label="审核拒绝" name="7"></el-tab-pane>
                  <el-tab-pane label="上架" name="2"></el-tab-pane>
                  <el-tab-pane label="下架" name="3"></el-tab-pane>
                </el-tabs>
               <!--  <el-button-group>
                  <el-button plain @click="handTabChange(1)" label="全部" autofocus>全部</el-button>
                  <el-button plain @click="handTabChange(4)" label="预审核">预审核</el-button>
                  <el-button plain @click="handTabChange(5)" label="待审核">待审核</el-button>
                   <el-button plain @click="handTabChange(6)" label="审核通过">审核通过</el-button>
                  <el-button plain @click="handTabChange(7)" label="审核拒绝">审核拒绝</el-button>
                  <el-button plain @click="handTabChange(2)" label="允许销售">上架</el-button>
                  <el-button plain @click="handTabChange(3)" label="不可销售">下架</el-button>
                </el-button-group> -->
              </el-form-item>
            </el-row>
          </div>
        </el-form>
      </div>
      <div class="toolbar" style="float:right;padding-right:15px;">
        <table-column-filter-dialog  ref="tableColumnFilterDialog" :columns="columns" @handleFilterColumns="handleFilterColumns" ></table-column-filter-dialog>
      </div>
      <!--表格内容栏-->
      <cy-table
        :height="350"
        :operationWidth="300"
        :content="pageResult"
        :columns="filterColumns"
        :totalSize="totalSize"
        :showDeleteOperation="false"
        :showBatchDelete="false"
        @findPage="findPage"

        :showLifeCycleOperation="false"
        @handleEdit="handleEdit"
        @updateProductInfo="updateProductInfo"
        :btnList="btnList"
        @handSubmit="handSubmit"
        @handExamine="handExamine"
        @handReason="handReason"
        @cancelhandExamine="handSubmit"
        :showCustomOperation="false"
        :customLabel="'提交'"
        @handleCustom="handleCustomSubmit1"
        :btnListTwo="btnListTwo"
        @handleStopSale="handleStopSale"
        @handleSale="handleSale"
        ref="CyTable"
      ></cy-table>   <!--@handleLifeCycle="handleLifeCycle"   :btnListOne="btnListOne"  -->
    </div>
    <!--商品类目-->
    <el-dialog
      title="商品类目"
      width="40%"
      height="800px"
      :visible.sync="categoryDialogVisible"
      :close-on-click-modal="false"
    >
      <el-tree
        :data="categoryData"
        :highlight-current="true"
        :props="defaultProps"
        @node-click="thisTreeClick"
        ref="tree"
        style="margin-top: 40px;"
      ></el-tree>
      <div slot="footer" class="dialog-footer" style="text-align:center;margin-top: 40px;">
        <el-button
          :size="size"
          @click.native="categoryDialogVisible = false"
        >{{ $t("action.cancel") }}</el-button>
        <el-button :size="size" type="primary" @click="submitCategoryForm" :loading="editLoading">
          {{ $t("action.submit")
          }}
        </el-button>
      </div>
    </el-dialog>
  <!-- 商品品牌 -->
  <el-dialog title="选择商品品牌" :visible.sync="dialogQueryBrand" @close="cancel" width="50%">
            <div class="search-wrap">
                <el-form :inline="true" :model="searchFilters" ref="searchFilters" >
                    <el-form-item label="品牌名称" align="left">
                        <el-input v-model="searchFilters.name" placeholder="请输入商品品牌"></el-input>
                    </el-form-item>
                     <el-form-item align="center">
                    <el-button size="mini" @click="queryBrand">查询</el-button>
                    <el-button size="mini" @click="searchFiltersResetForm()">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div class="table-wrap">
                <el-table :data="brandList" highlight-current-row height="30%" @current-change="handleSelectionChange">
                    <!-- <el-table-column align="center" type="selection" width="55"></el-table-column> -->
                    <el-table-column v-show="false" align="center" prop="id" label="品牌id" ></el-table-column>
                    <el-table-column align="center" prop="name" label="品牌名称" width="160"></el-table-column>
                    <el-table-column align="center" prop="englishName" label="品牌英文名" width="160"></el-table-column>
                    <el-table-column align="center" prop="alias" label="品牌别名" width="160"></el-table-column>
                    <!-- <el-image style="width: 100px; height: 100px" :src="pic" fit="fit"></el-image> -->
                    <el-table-column align="center" prop="pic" label="品牌LOGO" showImg="true">
                      <template slot-scope="pic">
                    　　　　<img src="pic" width="40" height="40" />
                    　</template>
                    </el-table-column>
                </el-table>
                <!--分页栏-->
                <div class="toolbar" style="padding:10px;">
                    <el-pagination layout="total, prev, pager, next, jumper,sizes" @current-change="refreshPageRequest" @size-change="handleSizeChange" :current-page="pageRequest.pageNum" :page-size="pageRequest.pageSize" :total="totalSize" style="float:right;" :page-sizes="[10, 20, 30, 40]"></el-pagination>
                </div>
            </div>
            <div slot="footer" class="dialog-footer" style="text-align: center">
                <el-button @click="addDialogBrand">保 存</el-button>
                <el-button type="primary" @click="cancel">取 消</el-button>
            </div>
        </el-dialog>

    <!--审核界面-->
    <el-dialog
      :title="operation?'商品审核':'查看原因'"
      width="40%"
      height="800px"
      :visible.sync="editDialogVisible1"
      v-if="editDialogVisible1"
      :close-on-click-modal="false"
    >
      <el-form
        :model="dataForm1"
        label-width="100px"
        :rules="dataFormRules1"
        ref="dataForm1"
        :size="size"
        :inline="true"
      >
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataForm1.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="审核结果:" style="margin-top: 20px;" prop="status">
          <template>
          <el-radio v-model="dataForm1.status" label="2" @change="selectChangeChecked">审核通过</el-radio>
          <el-radio v-model="dataForm1.status" label="3" @change="selectChangeChecked">审核不通过</el-radio>
          </template>

        </el-form-item>
        <el-col>
          <el-form-item label="拒绝原因:" v-if="selectChangeStatus" prop="auditMessage">
            <el-input
              type="textarea"
              style="width:200%;"
              v-model="dataForm1.auditMessage"
              :disabled="!operation"
              maxlength="200"
              :autosize="{ minRows: 2, maxRows: 4}"
              auto-complete="off"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center;margin-top: 40px;">
        <el-button :size="size" @click.native="editDialogVisible1 = false">{{ $t("action.cancel") }}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="submitForm1"
          :loading="editLoading"
          v-show="operation"
        >
          {{
          $t("action.submit")
          }}
        </el-button>
      </div>
    </el-dialog>
    <!--商品生命周期-->
   <!--  <el-dialog title="商品生命周期" width="40%" height="800px" :visible.sync="lifeCycleDialogVisible" :close-on-click-modal="false" >
      <el-form :model="dataLifeCycleForm" label-width="100px" ref="dataLifeCycleForm" :size="size" :inline="true" >
        <el-form-item label="ID" prop="id" v-if="false">
          <el-input v-model="dataLifeCycleForm.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="生命周期:" style="margin-top: 20px;" prop="lifeCycle">
          <el-select v-model="dataLifeCycleForm.lifeCycle" placeholder="生命周期">
            <el-option
              v-for="item in lifeCycleOption"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center;margin-top: 40px;">
        <el-button
          :size="size"
          @click.native="lifeCycleDialogVisible = false"
        >{{ $t("action.cancel") }}</el-button>
        <el-button :size="size" type="primary" @click.native="submitLifeCycleForm">
          {{
          $t("action.submit")
          }}
        </el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import CyTable from "@/views/Pages/Product/BusinessProductTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";

export default {
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      dataLifeCycleForm: {
        id: "",
        lifeCycle: ""
      },
      dialogQueryBrand:false,//
/*       lifeCycleDialogVisible: false, //商品生命周期 */
      lifeCycleOption: [
        { key: "1", value: "初始期" },
        { key: "2", value: "培养期" },
        { key: "3", value: "上升期" },
        { key: "4", value: "衰退期" },
        { key: "5", value: "清退期" },
        { key: "6", value: "屏蔽期" }
      ],
      categoryId: "",
      productId: "",
      sourceTypeOptions: [{ key: 1, value: "平台" }, { key: 2, value: "商家" }],
/*       isSaleOptions: [{ key: 1, value: "是" }, { key: 0, value: "否" }], */
      productOptions: [{ key: 1, value: "mini专卖" }, { key: 2, value: "商户003" }],
      combineTypeOptions: [
        { key: 0, value: "固定组合" },
        { key: 1, value: "可选组合" }
      ],
      typeOptions: [
        {
          value: 1,
          label: "实体商品"
        },
        {
          value: 2,
          label: "虚拟商品"
        },
        {
          value: 3,
          label: "海淘商品"
        }
      ],
      defaultProps: {
        children: "categoryList",
        label: "name"
      },
      mineStatus:[],
      statusList: [],
      radio: [],
      activeName: "1",
      editorOption: {},
      typeOfProductList: [
        {
          value: "",
          label: "全部"
        },
        {
          value: 1,
          label: "普通商品"
        },
        {
          value: 2,
          label: "系列虚品"
        }
      ],
      typeList: [
        {
          value: 1,
          label: "实体商品"
        },
        {
          value: 2,
          label: "虚拟商品"
        },
        {
          value: 3,
          label: "海淘商品"
        }
      ],
      brandList: [],
      guaranteeList: [],
      saleCalcUnitList: [],
      editableTabsValue: "1",
      editableTabs: [],
      size: "small",
      filters: {
        chineseName: "",
        code: "",
        thirdProductCode: "",
        brandId: "",
        brandName: "",
        categoryIdArr: [],
        selectCategoryData:[],
        mineStatus:null,
        combineType: "",
        canSale: "",
        type: "",
      },
      columns: [
      /*   { prop: "id", label: "序号", minWidth: 80 }, */
        { prop: "pictureUrl", label: "主图", minWidth: 100, showImg: true },
        { prop: "chineseName", label: "商品名称", minWidth: 110 },
        { prop: "code", label: "商品编码", minWidth: 110 },
        { prop: "typeOfProduct", label: "商品形式", minWidth: 110, formatter: this.formatProductType },
        { prop: "totalStock", label: "总库存", minWidth: 100 },
        { prop: "salePriceWithTax", label: "零售价", minWidth: 100 },
       /*  { prop: "isDistribute", label: "是否分发到店铺", minWidth: 140, formatter: this.formatIsDistribute }, */
        { prop: "name", label: "商品品牌", minWidth: 110 },
        { prop: "status",label: "审核状态",minWidth: 110,formatter: this.formatStatus},
      /*   { prop: "canSale",label: "允许销售",minWidth: 110,formatter: this.formatCanSale}, */
        { prop: "fullNamePath", label: "商品类目", minWidth: 180 },
/*         {prop: "type",label: "商品类型",minWidth: 120,formatter: this.formatType}, */
        {prop: "merchantCode",label: "商家编码",minWidth: 110},
        {prop: "merchantName",label: "商家名称",minWidth: 110},
        {prop: "sourceType",label: "商品来源",minWidth: 120,formatter: this.formatSource},
        {prop: "canSale",label: "上下架状态",minWidth: 130,formatter: this.formatCanSale},
        ],

      btnList: [{customLabel: "提交",isShowMethod: 0,method: "handSubmit"},
        {customLabel: "审核",isShowMethod: 1,method: "handExamine"},
        {customLabel: "查看原因",isShowMethod: 3,method: "handReason"}],
      btnListOne: [{saleLabel: "上架",saleMethod: 0,sale: "handleStopSale"},
                     {saleLabel: "下架",saleMethod: 1,sale: "handleSale"}],
      btnListTwo: {customLabel: "撤销提交",isShowMethod: 1,method: "cancelhandExamine"},
      filterColumns: [],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: [],
      selections: [],
      totalSize: 0,
      operation: false, // true:审核, false:查看原因
      editDialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,
      editDialogVisibleDetail: false,
      categoryDialogVisible: false,
      categoryData: [],//
      selectCategoryData:[],
      editDialogVisible1: false,
      dataFormRules1: {
        status: [
          { required: true, message: "请输入审核状态", trigger: "change" }
        ],
        auditMessage: [
          { required: true, message: "请输入拒绝原因", trigger: "blur" }
        ]
      },
      dataForm1: {
        id: "",
        status: "",
        auditMessage: ""
      },
      statusData: [
        {
          value: "2",
          label: "审核通过"
        },
        {
          value: "3",
          label: "审核拒绝"
        }
      ],
      selectChangeStatus: false,
      searchFilters: { // 商品品牌查询
        name: null,//商品名称
      },
    };
  },
  methods: {
    //商品品牌搜索框取消
    cancel() {
      this.dialogQueryBrand = false
      this.searchFilters.name = null;
    },
    //生命周期提交
   /*  submitLifeCycleForm() {
      let this_ = this;
      this.$refs.dataLifeCycleForm.validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            let params = Object.assign({}, this.dataLifeCycleForm);
            this.utils.request.updateProductInfo(params, function(data) {
              if (data.code == "0000") {
                this_.$message({ message: "操作成功", type: "success" });
                this_.lifeCycleDialogVisible = false;
              } else {
                this_.$message({
                  message: "操作失败, " + data.msg,
                  type: "error"
                });
              }
              this_.findPage();
            });
          });
        }
      });
    }, */
    //生命周期
/*     handleLifeCycle: function(param) {
      this.lifeCycleDialogVisible = true;
      this.dataLifeCycleForm = {
        id: param.row.id,
        lifeCycle: param.row.lifeCycle.toString()
      };
    }, */

    handleCheckChange(click, checked) {
      let res = checked.checkedNodes;
      let arrLabel = [];
      let arr = checked.checkedKeys;
      res.forEach(item => {
        arrLabel.push(item.name);
      });
      this.filters.categoryIdArr = arr;
      this.mineStatus = arrLabel;
    },
    /**查询商品品牌 */
    queryBrand(params){
      let this_ = this;
       if (params == undefined || params == null) {
                params = {
                    pageNum: this_.pageRequest.pageNum,
                    pageSize: this_.pageRequest.pageSize
                };
            }
            if (this_.searchFilters == undefined || this_.searchFilters == null) {
                this_.searchFilters = {};
            }
            this_.searchFilters.start = params.pageNum;
            this_.searchFilters.limit = params.pageSize;
      this.utils.request.queryBrandList(this_.searchFilters, function(res) {
        if (res.data != null) {
          this_.brandList = res.data.rows;
          this_.totalSize = Number(res.data.total);
          this_.dialogQueryBrand = true;
        }
      });
    },
    // 每页数据刷新
    refreshPageRequest: function (pageNum) {
        this.pageRequest.pageNum = pageNum;
        this.queryBrand(this.pageRequest1);
    },
    // 每页条数刷新
    handleSizeChange: function (pageSize) {
        this.pageRequest.pageSize = pageSize;
        this.queryBrand();
    },
    //给品牌设置参数
    addDialogBrand(){
      let this_ = this;
      this_.searchFilters.name = null;
      if(this_.selections!=null ) this_.filters.brandId = this_.selections.id;this_.filters.brandName = this_.selections.name;
      this.dialogQueryBrand = false
    },
    // 获取分页数据
    findPage: function(params) {
      let this_ = this;
      if (params == undefined || params == null) {
        params = {
          pageNum: this_.pageRequest.pageNum,
          pageSize: this_.pageRequest.pageSize
        };
      }
      if (this_.filters == undefined || this_.filters == null) {
        this_.filters = {};
      }
      this_.filters.start = params.pageNum;
      this_.filters.limit = params.pageSize;
      this.utils.request.queryPageProductManagement(this_.filters, function(
        res
      ) {
        if (res.code == "0000") {
          this_.pageResult = res.data.rows;
          this_.totalSize = Number(res.data.total);
        } else {
          this_.$message({ message: "操作失败, " + res.msg, type: "error" });
        }
      });
    },
    // 分配
    handleDistribution() {
      this.$router.push({
        path: "/ProductDistribution"
      });
    },
    // 提交
    handSubmit: function(data) {
      let this_ = this;
      if (data.row.salePriceWithTax < 1) {
        this_.$message({ message: "请先填写商品售价", type: "error" });
        return;
      }
      let params = {};
      params.id = data.row.id;
      if (data.row.status == 0) {
        params.status = 1;
      }else if(data.row.status == 1){
          params.status = 0;
      }
      this.utils.request.updateProductInfo(params, function(data) {
        if (data.code == "0000") {
          this_.$message({ message: "操作成功", type: "success" });
          this_.findPage(1);
        } else {
          this_.$message({ message: "操作失败, " + res.msg, type: "error" });
        }
      });
    },
    // 查看原因时显示提交
    handleCustomSubmit1: function(data) {
      let this_ = this;
      if (data.row.salePriceWithTax < 1) {
        this_.$message({ message: "请先填写商品售价", type: "error" });
        return;
      }
      let params = {};
      params.id = data.row.id;
      params.status = 1;
      this.utils.request.updateProductInfo(params, function(data) {
        if (data.code == "0000") {
          this_.$message({ message: "操作成功", type: "success" });
          this_.findPage(1);
        } else {
          this_.$message({ message: "操作失败, " + res.msg, type: "error" });
        }
      });
    },
    // 审核弹窗隐藏拒绝原因
    selectChangeChecked(value) {
      if (value == 3) {
        this.selectChangeStatus = true;
      } else {
        this.selectChangeStatus = false;
      }
    },
    // 审核弹窗
    handExamine: function(data) {
      let this_ = this;
      this_.operation = true;
      this_.editDialogVisible1 = true;
      this.selectChangeStatus = false;
      this_.dataForm1 = {
        id: "",
        status: "",
        auditMessage: ""
      };
      if (this_.$refs["dataForm1"]) {
        this_.$refs["dataForm1"].clearValidate();
      }
      this_.dataForm1.id = data.row.id;
    },
    // 审核提交
    submitForm1: function() {
      let this_ = this;
      this_.$refs.dataForm1.validate(valid => {
        if (valid) {
          let params = {};
          params.id = this_.dataForm1.id;
          params.status = this_.dataForm1.status;
          params.auditMessage = this_.dataForm1.auditMessage;
          this.utils.request.updateProductInfo(params, function(data) {
            if (data.code == "0000") {
              this_.editDialogVisible1 = false;
              this_.$message({ message: "操作成功", type: "success" });
              this_.findPage(1);
            } else {
              this_.$message({
                message: "操作失败, " + res.msg,
                type: "error"
              });
            }
          });
        }
      });
    },
    cancelhandExamine(){

    },
    // 查看原因
    handReason: function(data) {
      let this_ = this;
      this_.operation = false;
      this_.dataForm1.status = "3";
      this_.dataForm1.auditMessage = data.row.auditMessage;
      this_.editDialogVisible1 = true;
      this_.selectChangeStatus = true;
    },
    // 下架
     handleSale: function(data) {
      let this_ = this;
      this_
        .$confirm("确认不可销售吗？", "提示", {
          type: "warning"
        })
        .then(() => {
          let params = {};
          params.id = data.row.id;
          params.canSale = 0;
          this_.utils.request.updateProductInfo(params, function(data) {
            if (data.code == "0000") {
              this_.$message({ message: "操作成功", type: "success" });
              this_.findPage(1);
            } else {
              this_.$message({
                message: "操作失败, " + res.msg,
                type: "error"
              });
            }
          });
        });
    },
    // 上架
    handleStopSale: function(data) {
      let this_ = this;
      console.log(data.row.status)
      if (data.row.status != 2) {
        this_.$message({
                message: "未审核通过商品不能上架",
                type: "error"
        });
      } else {
        this_
        .$confirm("确认允许销售吗？", "提示", {
          type: "warning"
        })
        .then(() => {
          let params = {};
          params.id = data.row.id;
          params.canSale = 1;
          this_.utils.request.updateProductInfo(params, function(data) {
            if (data.code == "0000") {
              this_.$message({ message: "操作成功", type: "success" });
              this_.findPage(1);
            } else {
              this_.$message({
                message: "操作失败, " + res.msg,
                type: "error"
              });
            }
          });
        });
      }
    },
    // 修改商品信息
    updateProductInfo: function(params) {
      if (params.row.salePriceWithTax > 0) {
        let param = {
          status: 1,
          id: params.row.id
        };
        let this_ = this;
        this.utils.request.updateProductInfo(param, function(data) {
          if (data.code == "0000") {
            this_.$message({ message: "操作成功", type: "success" });
            this_.findPage(1);
          } else {
            this_.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        });
      } else {
        this.$message({ message: "请先填写商品售价", type: "error" });
      }
    },
    // 批量删除
    handleDelete: function(data) {
      if (data != null && data.params != null && data.params.length > 0) {
        let ids = data.params.map(item => item.id).toString();

        let params = {};
        params.t = "feedback";
        params.ids = ids;
        let this_ = this;
        this.utils.request.deleteUserInfo(params, function(res) {
          if (res.code == "0000") {
            this_.$message({ message: "操作成功", type: "success" });
            this_.findPage(null);
          } else {
            this_.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        });
      }
    },
    // 显示新增界面
    handleAdd: function(productId) {
      this.$router.push({
        path: "/BusinessProductInfo/" + 0
      });
    },
    // 显示编辑界面
    handleEdit: function(params) {
      this.$router.push({
        path: "/BusinessProductInfo/" + params.row.id
      });
    },
    //主界面查询所有商品类目
    queryBehindCategory: function(data) {
      let params = {};
      let this_ = this;
      this.utils.request.queryBehindCategory(params, function(data) {
        this_.categoryData = data.data;
        this_.selectCategoryData = data.data;
      });
    },
    selectCategory() {
      this.categoryDialogVisible = true;
      this.queryBehindCategory();
    },
    thisTreeClick: function(data) {
      this.categoryId = data.id;
      this.filters.categoryId = data.id;
      this.productCategory = data.fullNamePath;
      this.filters.fullNamePath = data.fullNamePath;
    },
    handTabChange(tab, event) {
      let param = tab.name;
      if (param == 1) {
        this.filters.canSale = "";
        this.filters.status = "";
        this.findPage();
      } else if (param == 2) {
        this.filters.canSale = 1;
        this.filters.status = "";
        this.findPage();
      } else if (param == 3) {
        this.filters.canSale = 0;
        this.filters.status = "";
        this.findPage();
      } else if (param == 4) {
        this.filters.canSale = "";
        this.filters.status = "0";
        this.findPage();
      } else if (param == 5) {
        this.filters.canSale = "";
        this.filters.status = "1";
        this.findPage();
      } else if (param == 6) {
        this.filters.canSale = "";
        this.filters.status = "2";
        this.findPage();
      } else if (param == 7) {
        this.filters.canSale = "";
        this.filters.status = "3";
        this.findPage();
      }
    },
    // format数字
    formatProductType: function(row, column, cellValue) {
      if (cellValue == 1) {
        return "普通商品";
      } else if (cellValue == 2) {
        return "系列子品";
      }
    },
    formatType: function(row, column, cellValue) {
      if (cellValue === 1) {
        return "实体商品";
      } else if (cellValue === 2) {
        return "虚拟商品";
      } else if (cellValue === 3) {
        return "虚拟组合";
      } else if (cellValue === 4) {
        return "实物组合";
      }
    },
    formatIsDistribute: function(row, column, cellValue, index) {
      if (cellValue > 0) {
        return "是";
      } else {
        return "否";
      }
    },
    formatCanSale: function(row, column, cellValue, index) {
      if (cellValue == 0) {
        return "下架";
      } else if (cellValue == 1) {
        return "上架";
      }
    },
    formatStatus: function(row, column, cellValue, index) {
      if (cellValue == 0) {
        return "预审核";
      } else if (cellValue == 1) {
        return "待审核";
      } else if (cellValue == 2) {
        return "审核通过";
      } else if (cellValue == 3) {
        return "审核不通过";
      }
    },
    formatSource: function(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "平台";
      } else if (cellValue == 2) {
        return "商家";
      }
    },
    submitCategoryForm: function() {
      this.categoryDialogVisible = false;
    },
    // 重置
    resetForm(formName) {
      this.filters = {};
      this.queryBehindCategory();
      this.findPage();
    },
    // 商品品牌搜索内容重置
    searchFiltersResetForm () {
      let that = this;
      that.searchFilters.name = null;
      that.queryBrand();
    },
    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      let temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },
    handleSelectionChange(val) {
      this.selections = val;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "意见反馈下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },
  mounted() {
    this.initColumns();
    this.queryBehindCategory();
  }
};
</script>

<style scoped lang="scss">
/* 设置顶部筛选条件 */
// .commonStyle {
//   width: 160px;
// }

// .commonStyle el-select {
//   width: 100%;
// }

#hiddenId {
  height: 20px;
  border-bottom: 1px solid #ccc;
  margin-bottom: 20px;
}

#middleInfo {
  border-bottom: 1px solid #ccc;
  margin-bottom: 20px;
}

#rowMargin {
  margin-bottom: 14px;
}

#secondRow {
  border-bottom: 1px solid #ccc;
}

#underSelector {
  border-bottom: 1px solid #ccc;
  margin-bottom: 20px;
}

#footerButton {
  padding-top: 20px;
}

</style>
